package xyz.robinbingo.effectivejava.chapter04.item20;

import cn.hutool.core.lang.Console;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.AbstractList;
import java.util.AbstractMap;
import java.util.List;
import java.util.Objects;

/**
 * @author Robin
 * @date 2019/03/21 15:33
 **/
@RunWith(SpringRunner.class)
@SpringBootTest
public class Item20 {

    // Concrete implementation built atop skeletal implementation
    static List<Integer> intArrayAsList(int[] a) {
        Objects.requireNonNull(a);
        // The diamond operator is only legal here in Java 9 and later
        // If you're using an earlier release, specify <Integer>
        return new AbstractList<>() {
            @Override
            public Integer get(int i) {
                return a[i]; // Autoboxing (Item 6)
            }

            @Override
            public Integer set(int i, Integer val) {
                int oldVal = a[i];
                a[i] = val; // Auto-unboxing
                return oldVal; // Autoboxing
            }

            @Override
            public int size() {
                return a.length;
            }
        };
    }

    @Test
    public void test00() {
        Singer singer = s -> "sing";
        int sss = singer.a("sss");
        String sing = singer.sing(new Song());
        String b = Singer.b(9);
        Console.log(b);
        Console.log(sss);
        Console.log(sing);
    }

    @Test
    public void test01() {
        AbstractMap.SimpleEntry<Integer, Integer> simpleEntry = new AbstractMap.SimpleEntry<>(1, 1);
    }
}
